package com.hwqsdk.myapplication;

import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.Toast;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.core.BasePopupView;
import com.lxj.xpopup.impl.LoadingPopupView;
import com.lxj.xpopup.interfaces.SimpleCallback;
import com.qmuiteam.qmui.widget.dialog.QMUITipDialog;


public class MainActivity extends AppCompatActivity {


    private String course = "";
    private EditText edtName;
    private Button btnCommit;
    private EditText edtIdNum;
    private RadioGroup radioGroup;
    private CheckBox chkM;
    private CheckBox chkE;
    private CheckBox chkMD;
    private final String TAG = "TAG";
    private LoadingPopupView loadingPopupView;
    private boolean isFail = true;
//ZHL add 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        new QMUITipDialog.Builder(this).setIconType(QMUITipDialog.Builder.ICON_TYPE_LOADING).create(false).show();
//        loadingPopupView = new XPopup.Builder(MainActivity.this)
//                .dismissOnBackPressed(false).dismissOnBackPressed(false).setPopupCallback(new SimpleCallback() {
//                    @Override
//                    public void onDismiss(BasePopupView popupView) {
//                        if (isFail)
//                            Toast.makeText(MainActivity.this, "加载失败", Toast.LENGTH_SHORT).show();
//                    }
//                }).asLoading("正在加载中");
        initView();
        btnCommit.setOnClickListener(v -> {
            Log.i(TAG, "MainActivity: " + getTaskId());
            loadingPopupView.delayDismiss(4000);
            loadingPopupView.show();
//            new QMUILoadingView(this)
//            Intent intent = new Intent(GB.TAG);
//            intent.setComponent(new ComponentName(getPackageName(), "com.hwqsdk.myapplication.GB"));
//            sendBroadcast(intent);
//            startActivity(new Intent(MainActivity.this, MainActivity.class));
//            show();
//            Bundle bundle = new Bundle();
//            MySDK.launchSdkNoAnimation(bundle, LaunchMethod.LOGIN);
        });
//        RegexUtils.isTel("121321312");

    }

    @Override
    protected void onStart() {
        super.onStart();
        Log.i(TAG, "onStart: ");
    }


    @Override
    protected void onRestart() {
        super.onRestart();

        Log.i(TAG, "onRestart: " + (loadingPopupView == null));
    }

    GB gb;

    @Override
    protected void onResume() {
        super.onResume();
//        BlankFragment blankFragment = new BlankFragment();
//        getSupportFragmentManager().beginTransaction().add(blankFragment, "").commit();
//        gb = new GB();
//        IntentFilter filter = new IntentFilter(AAA);
//        registerReceiver(gb, filter);
        Log.i(TAG, "onResume: ");
    }

    @Override
    protected void onPause() {
        super.onPause();
//        Standard
        // task
//        model
//        repository
//        Presenter
//        data
//        SingleInstance
//        unregisterReceiver(gb);
        Log.i(TAG, "onPause: ");
    }

    @Override
    protected void onStop() {
        loadingPopupView.destroy();
        super.onStop();

        Log.i(TAG, "onStop: ");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        Log.i(TAG, "onDestroy: ");
    }

    private void show() {
        AlertDialog alertDialog = new AlertDialog.Builder(this).create();
        alertDialog.setTitle("学生的全部信息");

        String sex;
        if (radioGroup.getCheckedRadioButtonId() == R.id.radMan)
            sex = "男";
        else sex = "女";

        if (chkE.isChecked()) course += "英语 ";
        if (chkM.isChecked()) course += "数学 ";
        if (chkMD.isChecked()) course += "模电 ";
        if (course.equals("")) course = "无";
        alertDialog.setMessage("姓名：" + edtName.getText().toString() +
                ",学号：" + edtIdNum.getText().toString() + "，性别:" + sex + "\n选修课程：" + course);
        alertDialog.show();
        course = "";
    }


    private void initView() {
        edtName = (EditText) findViewById(R.id.edtName);
        btnCommit = (Button) findViewById(R.id.btnCommit);
        edtIdNum = (EditText) findViewById(R.id.edtIdNum);
        radioGroup = (RadioGroup) findViewById(R.id.radioGroup);
        chkM = (CheckBox) findViewById(R.id.chkM);
        chkE = (CheckBox) findViewById(R.id.chkE);
        chkMD = (CheckBox) findViewById(R.id.chkMD);
    }
}